package com.liang.threaddemo6;

public class MyThread extends Thread {
    private static int ticket = 100;
    private static Object obj = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (ticket == 0) {
                    break;
                }else{
                    try {
                        sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticket--;
                    System.out.println(getName()+"正在卖票，还剩"+ticket+"张票");
                }
            }
        }
    }
}
